package com.gr.controller;

import com.gr.entity.Type;
import com.gr.service.BookService;
import com.gr.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private TypeService typeService;
    @Autowired
    private BookService bookService;
    @RequestMapping("/selectAllType")
    public String selectAllType(Model model){
        List<Type> types = typeService.selectAllType();
        model.addAttribute("types",types);
        return "/addBook.jsp";//这里要加斜杠
    }
    @RequestMapping("/selectAllTypeAndBooKNum")
    public String selectAllTypeAndBooKNum(Model model){
        List<Type> types = typeService.selectAllTypeAndBooKNum();//调错方法了
        model.addAttribute("types",types);
        return "/categorylist.jsp";//这里要加斜杠
    }
    @RequestMapping("/deleteTypeById")
    public String deleteTypeById(Integer id){
        typeService.deleteTypeById(id);
        bookService.deleteBookByTid(id);
        return "/type/selectAllTypeAndBooKNum.do";
    }

}
